package com.wuyi.controller;

import com.wuyi.pojo.bo.CommentBO;
import com.wuyi.pojo.bo.CommentsBO;
import com.wuyi.service.CommentService;
import com.zc.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName CommentController.java
 * @Description 评论相关接口
 * @createTime 2021年11月03日 23:54:00
 */

@Api(value = "评论",tags = {"用于评论的相关接口"})
@RestController
@RequestMapping("post")
public class CommentController {

    public final static Logger logger = LoggerFactory.getLogger(PostController.class);

    @Autowired
    private CommentService commentService;


    @ApiOperation(value = "新增评论（可调试）", notes = "新增评论（可调试）", httpMethod = "POST")
    @PostMapping("/addComment")
    public JSONResult addComment(@RequestBody CommentBO commentBO) {

        if (StringUtils.isBlank(commentBO.getCommentText())) {
            return JSONResult.errorMsg("评论内容不能为空");
        }
        if (commentBO.getCommentText().length() > 300) {
            return JSONResult.errorMsg("评论内容超出限制字数");
        }
        return commentService.addComment(commentBO);
    }


    @ApiOperation(value = "删除个人发表评论（可调试）", notes = "删除个人发表（可调试）", httpMethod = "POST")
    @PostMapping("/deleteComment")
    public JSONResult deleteComment(@RequestBody CommentsBO commentsBO) {

        if (null == commentsBO.getCommentId()) {
            return JSONResult.errorMsg("服务器出错");
        }
        return commentService.deleteComment(commentsBO.getCommentId());
    }


}
